'''
@Author: your name
@Date: 2019-06-24 11:32:40
LastEditTime: 2021-08-09 16:45:17
LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: /tinyms/tinyms-api/apps/admin/user/model.py
'''
from app import db

class Menu(db.Model):
    __tablename__ = 'sys_menu'
    menu_pk = db.Column(db.Integer,primary_key=True,autoincrement=True)
    menu_name = db.Column(db.String)
    menu_icon = db.Column(db.String)
    menu_parent = db.Column(db.String)
    menu_url = db.Column(db.String)
    menu_type = db.Column(db.String)
    menu_number = db.Column(db.String)
    menu_status = db.Column(db.String)
    sys_type = db.Column(db.String)
    menu_default = db.Column(db.String)


    def __repr__(self):
        return '<Menu %r>' % self.menu_pk

    def to_dict(items):
        lic = []
        for item in items:
            lic.append(
                {
                    'menu_pk':item.menu_pk,
                    'menu_name' : item.menu_name,
                    'menu_icon' : item.menu_icon,
                    'menu_parent' : item.menu_parent,
                    'menu_url' : item.menu_url,
                    'menu_type' : item.menu_type,
                    'menu_number' : item.menu_number,
                    'menu_status' : item.menu_status,
                    'sys_type' : item.sys_type,
                    'menu_default' : item.menu_default
                }
            )
        return lic
        
    def btns_to_array(items):
        lic = []
        for item in items:
            lic.append(item.menu_url)
        return lic